local parent, ns = ...
local psLib = ns.psLib;

local GenerateItemMessage = function(prefix,itemArg)
	local singeLineMessage = { strsplit("^", itemArg) };
	
	local result = prefix;
	for key,value in pairs(singeLineMessage) do	
		local itemID,price = strsplit(":", value);
		local n,l = GetItemInfo(itemID);
		if(l) then
			result =  result .. l;
			if(price) then result = result .. " " .. price .. " "; end;
		end
	end
	return result;
end

local SendTradeMessage = function(msg)
	if(not msg) then return; end;
	local _, channelName = GetChannelName(2);
	if(channelName) then
		SendChatMessage(msg, "CHANNEL", nil, "2");
	else
		SendChatMessage(msg, "CHANNEL", nil, "1");
	end
end

psLib:AddChatCommand("sell",function(...)
	local args = { ... };
	for _,value in pairs(args) do
		local msg = GenerateItemMessage("Продам: ", value);
		SendTradeMessage(msg);
	end
end
);

psLib:AddChatCommand("buy",function(...)
	local args = { ... };
	for _,value in pairs(args) do
		local msg = GenerateItemMessage("Куплю: ", value);
		SendTradeMessage(msg);
	end
end
);